package com.situ.mall.controller;

import com.situ.mall.pojo.Admin;
import com.situ.mall.pojo.Category;
import com.situ.mall.pojo.query.AdminQuery;
import com.situ.mall.pojo.query.CategoryQuery;
import com.situ.mall.service.ICategoryService;
import com.situ.mall.util.PageResult;
import com.situ.mall.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/category")
public class CategoryController {

    @Autowired
    ICategoryService categoryService;
    @RequestMapping("/selectTopCategory")
    public Result selectTopCategory(){
        List<Category> categories = categoryService.selectTopCategory();
        return Result.ok(categories);
    }

    @RequestMapping("/selectSecondCategoryByTopCategoryId")
    public Result selectSecondCategoryByTopCategoryId(Integer id){
        System.out.println(id);
        System.out.println("CategoryController.selectSecondCategoryByTopCategoryId");
        List<Category> list = categoryService.selectSecondCategoryByTopCategoryId(id);
        return Result.ok(list);
    }

    @RequestMapping("/list")
    public PageResult<Category> select(CategoryQuery categoryQuery){
        PageResult<Category> pageResult = categoryService.list(categoryQuery);
        return pageResult;
    }

    @RequestMapping("/deleteById")
    public Result deleteById(Integer id){
        categoryService.deleteById(id);
        return Result.ok("删除成功");
    }

    @RequestMapping("/deleteAll")
    public Result deleteAll(Integer[] ids){
        categoryService.deleteAll(ids);
        return Result.ok("删除成功");
    }

    @RequestMapping("/add")
    public Result add(Category category) {
        categoryService.add(category);
        return Result.ok("添加成功");
    }
}
